/**
 * 
 */
package edu.hadassah.store;

import edu.hadassah.store.client.IClient;
import edu.hadassah.store.client.IClientFactory;
import edu.hadassah.store.employee.IEmployee;
import edu.hadassah.store.employee.StoreEmployee;
import edu.hadassah.store.management.Client;
import edu.hadassah.store.management.ClientFactoryBasic;
import edu.hadassah.store.management.IStoreManagement;
import edu.hadassah.store.management.Order;
import edu.hadassah.store.management.OrderFactoryBasic;
import edu.hadassah.store.management.StoreManagement;
import edu.hadassah.store.order.IOrderInfo;
import edu.hadassah.store.order.OrderInfoImpl;
import edu.hadassah.store.repository.MapRepository;
import edu.hadassah.store.uniqueid.IUniqueId;
import edu.hadassah.store.uniqueid.UniqueId;

/**
 * @author persikov
 *
 */
public class Store {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		IStoreManagement storeManagement = createStoreManagement();
		IClientFactory clientFactory = new ClientFactoryBasic();
		
		System.out.println("Add employee 1");
		StoreEmployee employee1 = new StoreEmployee(new UniqueId("employee 1"));
		storeManagement.addEmployee(employee1);
		
		System.out.println("Add client 1");
		IClient client1 = clientFactory.createClient("client 1");
		storeManagement.addClient(client1);

		System.out.println("Add 2 orders to client 1");

		IOrderInfo order1 = new OrderInfoImpl(client1.getId(), "item1", 1);
		IUniqueId order1id = storeManagement.addOrder(order1);
		IOrderInfo order2 = new OrderInfoImpl(client1.getId(), "item2", 2);
		IUniqueId order2id = storeManagement.addOrder(order2);
		
		System.out.println("Update order 1");
		storeManagement.updateOrder(order1id, order1);
		
		System.out.println("Add employee 2");
		StoreEmployee employee2 = new StoreEmployee(new UniqueId("employee 2"));
		storeManagement.addEmployee(employee2);

		System.out.println("Update order 2");
		storeManagement.updateOrder(order2id, order2);

		System.out.println("Add client 2");
		IClient client2 = clientFactory.createClient("client 2");
		storeManagement.addClient(client2);
		
		
		System.out.println("Add orders 3 and 4 to client 2");
		IOrderInfo order3 = new OrderInfoImpl( client2.getId(), "item3", 3);
		IOrderInfo order4 = new OrderInfoImpl( client2.getId(), "item4", 4);
		IUniqueId order3id = storeManagement.addOrder(order3);
		IUniqueId order4id = storeManagement.addOrder(order4);
		System.out.println("Update order 3");
		storeManagement.updateOrder(order3id, order4);
		
		System.out.println("Remove employee 1");
		storeManagement.removeEmployee(employee1);
		
		System.out.println("Update order 4");
		storeManagement.updateOrder(order4id, order3);

		System.out.println("Order 4 removed=" + storeManagement.removeOrder(order4id));

		System.out.println("Update order 4 = "+storeManagement.updateOrder(order4id, order4));
		
		System.out.println("Order 4 removed second time=" + storeManagement.removeOrder(order4id));

		
		System.out.println("Client 2 removed = "+storeManagement.removeClient(client2.getId()));
		
		System.out.println("Order 3 removed=" + storeManagement.removeOrder(order3id));
		
		System.out.println("Client 2 removed = "+storeManagement.removeClient(client2.getId()));
		
		System.out.println("Update order 2 = " + storeManagement.updateOrder(order2id, order2));
		
//		Order orderTest = (Order)order1;
//		orderTest.updateOrderInfo(order4);
//		Client clientTest = new Client(client2.getId());
//		clientTest.addOrder(order4id);
	}

	/**
	 * @return
	 */
	private static IStoreManagement createStoreManagement() {
		StoreManagement storeManagementImpl = new StoreManagement();
		
		storeManagementImpl.setClientRepository(new MapRepository<IUniqueId, Client>());
		storeManagementImpl.setEmpoyeeRepository(new MapRepository<IUniqueId, IEmployee>());
		storeManagementImpl.setOrderRepository(new MapRepository<IUniqueId, Order>());
		storeManagementImpl.setOrderFactory(new OrderFactoryBasic());
		return storeManagementImpl;
	}

}
